package com.example.springboot.common;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;

import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2  // 启用Swagger 2
@EnableKnife4j  // 启用Knife4j增强
@Slf4j
public class Knife4jConfig {



     @Bean
     public Docket docket() {
         log.info(" Knife4j 接口文档初始化");

         ApiInfo apiInfo = new ApiInfoBuilder()
                 .title("图书管理系统 API 文档")
                 .description("Spring Boot + Knife4j 示例 ")
                 .version("1.0")
                 .build();

         return new Docket(DocumentationType.SWAGGER_2)
                 .apiInfo(apiInfo)
                 .select()
                 .apis(RequestHandlerSelectors.basePackage("com.example.springboot.controller"))
                 .paths(PathSelectors.any())
                 .build();
     }
}
